#ifndef __CHAINOFRESPONSIBILITY__
#define __CHAINOFRESPONSIBILITY__

#include <iostream>

using namespace std;

class Handler
{
	public:
		Handler(Handler* pSuccessor = NULL):a_pSuccessor(pSuccessor) {}

		virtual ~Handler() 
		{
			a_pSuccessor = NULL;
		}

		virtual void HandleRequest() = 0;

	protected:
		Handler* a_pSuccessor;

};


class ConcreteHandler1: public Handler
{
	public:
		ConcreteHandler1(Handler* pSuccessor = NULL):Handler(pSuccessor) {};

		virtual ~ConcreteHandler1() {};
		
		virtual void HandleRequest()
		{
			if (NULL == a_pSuccessor)
				cout << "handler1--request \n";
			else
				a_pSuccessor->HandleRequest();

			return;
		}
};

class ConcreteHandler2: public Handler
{
	public:
		ConcreteHandler2(Handler* pSuccessor = NULL):Handler(pSuccessor) {};

		virtual ~ConcreteHandler2() {};
		
		virtual void HandleRequest()
		{
			if (NULL == a_pSuccessor)
				cout << "handler2--request \n";
			else
				a_pSuccessor->HandleRequest();

			return;
		}
};

#endif
